package Day2025_03_14;

public class LeetCode413 {
    public int numberOfArithmeticSlices(int[] nums) {
        int n = nums.length;
        if (n == 0 || n == 1) return 0;
        int[] dp = new int[n];
        dp[0] = dp[1] = 0;
        for (int i = 2; i < n; i++) {
            int x = nums[i - 2],  y = nums[i - 1], z = nums[i];
            if (x - y == y - z) dp[i] = dp[i - 1] + 1;
            else dp[i] = 0;
        }
        int ret = 0;
        for (int x : dp) ret += x;
        return ret;
    }
}
